package com.x.example.page;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;

import com.x.example.PageRouteList;
import com.x.uikit.page.XPageManager;
import com.x.uikit.router.XRoute;


public class PagesRouteHandler {
    private final XPageManager mPageManager;

    public PagesRouteHandler(@NonNull XPageManager pageManager) {
        mPageManager = pageManager;
    }

    public void handRoute(@NonNull Intent intent) {
        XRoute route = intent.getParcelableExtra("route");
        if (route != null) {
            PageRouteList.navigate(route, mPageManager);
        }
    }

    public static void sendRouteToPage(@NonNull Context context, @NonNull XRoute route) {
        Intent it = new Intent(context, PageActivity.class);
        it.putExtra("route", route);
        context.startActivity(it);
    }

    public static XRoute getRoute(@NonNull Intent it) {
        return it.getParcelableExtra("route");
    }

    public static void sendRouteToPage(@NonNull Context context, @NonNull XRoute route, @NonNull Class<? extends Activity> clazz) {
        Intent it = new Intent(context, clazz);
        it.putExtra("route", route);
        context.startActivity(it);
    }
}
